<?php
defined('DS') or define( 'DS' , DIRECTORY_SEPARATOR);
$cacheFile = dirname(__FILE__).DS.'..'.DS.'..'.DS.'..'.DS.'cache'.DS.'news'.DS.'newsThumbShell.php';
if(is_file($cacheFile)){
	$cacheData = include_once($cacheFile);
}else{
	exit;
}
//load CRUB ENV
$config = include_once(dirname(__FILE__).DS.'..'.DS.'config.php');
$app=Yii::createConsoleApplication($config);
$app->commandRunner->addCommands(YII_PATH.'/cli/commands');
$env=@getenv('YII_CONSOLE_COMMANDS');
if(!empty($env))
	$app->commandRunner->addCommands($env);
$connection = Yii::app()->db;

$connecton = Yii::app()->db;
$sql = "select * from nc_news where `news_thumb` = '' or `news_thumb` IS NULL";
$nullWebThumb = $connecton->createCommand($sql)->queryAll();
$i = 0;
$data = array();
foreach($nullWebThumb as $key => $value){
	$cacheData += array($value['news_id']=>$value['link_url']);
}
$file_content = "<?php return ";
$file_content .= var_export($cacheData,true).';';
safe_file_put_contents($cacheFile, $file_content);
function safe_file_put_contents($filename, & $content) {
	$fp = fopen($filename, 'w+'); 
	if (!$fp)   return false;
	if (flock($fp, LOCK_EX))    fwrite($fp, $content); 
	flock($fp,LOCK_UN); 
	fclose($fp); 
	return true; 
} 